<template>
    <div class="fillContain">
        <head-top></head-top>
        <!--tabs标签-->
        <el-tabs v-model="tabsName" type="card" @tab-click="handleClick">
            <el-tab-pane label="报表清单" name="reportList">
                <el-container style="height: 600px; border: 1px solid #eee">
                    <el-aside width="220px" class="el-aside">
                        <!--可滚动-->
                        <report-tree v-on:refresh="initTable"></report-tree>
                    </el-aside>
                    <el-container>
                        <el-main>
                            <el-form :inline="true" ref="form" size="mini" label-width="">
                                <el-form-item label="报表名称：">
                                    <el-input
                                            placeholder="请输入报表名称"
                                            v-model="name"
                                            style="width: 150px"
                                            clearable>
                                    </el-input>
                                </el-form-item>
                                <el-form-item label="报表分类：">
                                    <el-select v-model="categorySelect.chooseValue" filterable clearable
                                               placeholder="请选择报表分类"
                                               @visible-change="initCategorySelect"
                                               style="width: 100px">
                                        <el-option
                                                v-for="item in categorySelect.options"
                                                :key="item.value"
                                                :label="item.name"
                                                :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="状态：">
                                    <el-select v-model="statusSelect.chooseValue" filterable clearable
                                               placeholder="请选择状态"
                                               @visible-change="initStatusSelect"
                                               style="width: 100px">
                                        <el-option
                                                v-for="item in statusSelect.options"
                                                :key="item.value"
                                                :label="item.name"
                                                :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-button size="mini" type="primary" @click="searchReport()">查询</el-button>
                                <div style="float: right">
                                    <el-button size="mini" v-if="staffId=='1'||isInArray3('reportMangerEditOrAdd')"
                                               @click="addReportConfig()">新增
                                    </el-button>
                                    &nbsp;
                                    <el-dropdown trigger="click"
                                                 v-if="staffId=='1'||isInArray3('reportMangerAllpublish')">
                                        <el-button size="mini" plain>
                                            批量操作<i class="el-icon-arrow-down el-icon--right"></i>
                                        </el-button>
                                        <el-dropdown-menu slot="dropdown">
                                            <el-dropdown-item :divided="true">
                                                <el-button size="mini" plain icon="el-icon-check" style="width: 120px"
                                                           @click="totalPublish()">合并发布
                                                </el-button>
                                            </el-dropdown-item>
                                            <el-dropdown-item :divided="true">
                                                <el-button size="mini" plain icon="el-icon-check" style="width: 120px"
                                                           @click="publishRows()">批量发布
                                                </el-button>
                                            </el-dropdown-item>
                                            <el-dropdown-item :divided="true">
                                                <el-button size="mini" icon="el-icon-delete" @click="batchDel()" plain
                                                           style="width: 120px">
                                                    批量删除
                                                </el-button>
                                            </el-dropdown-item>
                                        </el-dropdown-menu>
                                    </el-dropdown>
                                </div>
                            </el-form>
                            <el-table
                                    ref="reportManageTable"
                                    :data="tableData"
                                    border
                                    size="mini"
                                    height="480px"
                                    style="width: 100%"
                                    @selection-change="selectionChange">
                                <el-table-column
                                        type="selection">
                                </el-table-column>
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        prop="name"
                                        label="报表名称">
                                </el-table-column>
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        prop="categoryName"
                                        label="报表分类">
                                </el-table-column>
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        prop="status"
                                        label="状态"
                                        :formatter="statusFormatter">
                                </el-table-column>
                                <el-table-column
                                        show-overflow-tooltip
                                        prop="datasourceName"
                                        label="数据源">
                                </el-table-column>
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        prop="createTime"
                                        label="创建时间">
                                </el-table-column>
                                <el-table-column
                                        width="220px"
                                        label="操作">
                                    <template slot-scope="scope">
                                        <el-button size="mini" type="text" @click="authorityRow(scope.row)"
                                                   v-if="staffId=='1'||isInArray3('reportMangerPression')">权限
                                        </el-button>
                                        <!--修改按钮-->
                                        <el-button size="mini" type="text" @click="editRow(scope.row)"
                                                   v-if="staffId=='1'||isInArray3('reportMangerEditOrAdd')">修改
                                        </el-button>
                                        <!--删除按钮-->
                                        <el-button size="mini" type="text" @click="removeRow(scope.row)"
                                                   v-if="staffId=='1'||isInArray3('reportMangerDelete')">删除
                                        </el-button>
                                        <el-button size="mini" type="text" @click="publishRow(scope.row)"
                                                   v-if="staffId=='1'||isInArray3('reportMangerPublish')">发布
                                        </el-button>
                                        <el-button size="mini" type="text" @click="queryReport(scope.row)">查询报表
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <div class="block">
                                <el-pagination
                                        @size-change="handleSizeChange"
                                        @current-change="handleCurrentChange"
                                        :current-page="currentPage"
                                        :page-sizes="[10, 20, 50, 100]"
                                        :page-size="pageSize"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        :total="counts">
                                </el-pagination>
                            </div>
                        </el-main>
                        <!--<el-main>

                        </el-main>-->
                    </el-container>
                </el-container>
            </el-tab-pane>
            <el-tab-pane label="数据查询" name="searchMid" disabled>
                <span style="margin-left:500px">{{queryTitle}}</span>
                <!--报表查询弹窗-->
                <el-form
                        v-loading="loading"
                        element-loading-text="导出中"
                        element-loading-spinner="el-icon-loading"
                        element-loading-background="rgba(0, 0, 0, 0.8)"
                        :title=queryReportPops.name
                        :visible.sync="queryReportPops.centerDialogVisible"
                        width="80%"
                >
                    <el-form :inline="true" size="mini" label-width="" style="width: 95%;margin-left: 40px">
                <span v-for="paramsfor in queryReportPops.reportParamList.params">
                    <el-form-item :label=paramsfor.name v-if="paramsfor.type==1">
                        <el-input
                                :placeholder="'请输入'+paramsfor.name"
                                v-model=queryReportPops.paramMid[paramsfor.sqlName+paramsfor.type]
                                style="width: 150px"
                                clearable>
                        </el-input>
                    </el-form-item>
                    <el-form-item :label=paramsfor.name v-if="paramsfor.type==2">
                        <el-date-picker
                                v-model="queryReportPops.paramMid[paramsfor.sqlName+paramsfor.type]"
                                type="daterange"
                                value-format="yyyyMMdd"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :picker-options="pickerOptions">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item :label=paramsfor.name v-if="paramsfor.type==3">
                           <el-select v-model="queryReportPops.paramMid[paramsfor.sqlName+paramsfor.type]" clearable
                                      placeholder="请选择" style="width: 130px"
                                      @visible-change="initDictSelect(paramsfor.value)">
                                    <el-option
                                            v-for="item in queryReportPops.options"
                                            :key="item.value"
                                            :label="item.name"
                                            :value="item.value">
                                    </el-option>
                           </el-select>
                    </el-form-item>
                    <el-form-item :label=paramsfor.name v-if="paramsfor.type==4">
                           <el-select v-model="queryReportPops.paramMid[paramsfor.sqlName+paramsfor.type]" clearable
                                      placeholder="请选择" style="width: 130px"
                                      @visible-change="initSqlSelect(paramsfor.value)">
                                    <el-option
                                            v-for="item in queryReportPops.options"
                                            :key="item.value"
                                            :label="item.name"
                                            :value="item.value">
                                    </el-option>
                           </el-select>
                    </el-form-item>
                    <el-form-item label="账期" prop="cycle" v-if="paramsfor.type == 5">
                        <el-date-picker
                                v-model="queryReportPops.paramMid[paramsfor.sqlName+paramsfor.type]"
                                type="month"
                                value-format="yyyyMM"
                                placeholder="选择月">
                        </el-date-picker>
                    </el-form-item>
                </span>
                        <el-button size="mini" type="primary" icon="el-icon-search" @click="queryMidTable()">查询
                        </el-button>
                        <el-button size="mini" type="primary" @click="createMidExcel()">导出</el-button>
                    </el-form>
                    <!--<el-table-->
                    <!--ref="reportMidTable"-->
                    <!--:data="tableDataMid"-->
                    <!--border-->
                    <!--size="mini"-->
                    <!--height="400px"-->
                    <!--style="width: 80%"-->
                    <!--&gt;-->
                    <!--<el-table-column v-for="paramsfor in queryReportPops.reportParamList.views"-->
                    <!--:show-overflow-tooltip="true"-->
                    <!--:prop="paramsfor.field"-->
                    <!--:label=paramsfor.name-->
                    <!--&gt;-->
                    <!--</el-table-column>-->
                    <!--</el-table>-->
                    <preview-report ref="previewReport"
                                    v-bind:tableHeader="previewReportPops.tableHeader"
                                    v-bind:tableData="previewReportPops.tableData"
                                    style="width: 95%;margin-left: 40px"></preview-report>
                    <el-pagination
                            @size-change="handleSizeChangeMid"
                            @current-change="handleCurrentChangeMid"
                            :current-page="currentPageMid"
                            :page-sizes="[5, 10, 15, 20]"
                            :page-size="pageSizeMid"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="countsMid"
                            style="width: 95%;margin-left: 40px"
                    >
                    </el-pagination>
                </el-form>
            </el-tab-pane>
        </el-tabs>
        <!--tabs标签结尾-->
        <!--编辑弹窗-->
        <el-dialog
                :title="designPops.title"
                :visible.sync="designPops.centerDialogVisible"
                width="80%" :hidden="popsHide">
            <report-design @previewReport="preview" ref="reportDesign" @closePop="closePop"></report-design>
        </el-dialog>
        <!--预览弹窗-->
        <el-dialog
                :title="previewReportPops.title"
                :visible.sync="previewReportPops.centerDialogVisible"
                width="80%">
            <preview-report v-bind:tableHeader="previewReportPops.tableHeader"
                            v-bind:tableData="previewReportPops.tableData"></preview-report>
        </el-dialog>

        <!--权限弹窗-->
        <el-dialog
                title="权限设置"
                :visible.sync="permissionPops.centerDialogVisible"
                width="50%">
            <el-form :model="permissionForm" ref="permissionForm">
                <el-form-item label="设置用户列表:">
                    <el-select v-model="permissionForm.userId" filterable multiple placeholder="请选择用户">
                        <el-option v-for="item in userList" :key="item.userId" :label="item.name" :value="item.userId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="设置角色列表:">
                    <el-select v-model="permissionForm.roleId" filterable multiple placeholder="请选择角色">
                        <el-option v-for="item in roleList" :key="item.roleId" :label="item.roleName"
                                   :value="item.roleId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitPermission()">提交</el-button>
                    <el-button @click="closePermission()">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
    import HeadTop from '@/views/main-components/HeadTop.vue'
    import ReportTree from '@/views/main-components/ReportTree.vue'
    import ReportDesign from '@/views/my-components/ReportDesign.vue'
    import PreviewReport from '@/views/my-components/PreviewReport.vue'
    import {
        getReportList,
        publishReport,
        delReport,
        previewReport,
        getUserAndRoleList,
        setUserAndRole,
        getReportPermission,
        queryMid,
        createMidExcel,//导出
        publishMerge,
        searchMidBill
    } from '@/api/getData'
    import {ListSysDict} from '@/api/reportData'
    import {verificateReportMangerEditOrAdd, verificateReportMangerPression} from '@/api/user'

    export default {
        mounted: async function () {

        },
        created: function () {
            this.getUserAndRoleList();
            this.getUserInfo();
        },
        components: {
            ReportTree,
            HeadTop,
            ReportDesign,
            PreviewReport
        },
        data() {
            return {
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一年',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                loading: false,
                queryTitle: '',
                popsHide: false,
                name: '',
                categorySelect: {
                    chooseValue: '',
                    options: []
                },
                statusSelect: {
                    chooseValue: '',
                    options: []
                },
                designPops: {
                    title: '',
                    centerDialogVisible: false
                },
                previewReportPops: {
                    title: '',
                    centerDialogVisible: false,
                    tableData: [],
                    tableHeader: []
                },
                permissionPops: {
                    title: '',
                    centerDialogVisible: false,
                },
                permissionForm: {
                    userId: [],
                    roleId: [],
                    reportId: ''
                },
                queryReportPops: {
                    name: '',
                    reportParamList: [],
                    options: [],
                    paramMid: {
                        BILL_MONTH5: ''
                    },
                    headerList: [],
                    tableSql: '',
                    dsId: '',
                    header: '',
                    centerDialogVisible: false,
                },
                tableData: [],
                tableDataMid: [],//查询表报数据
                selectRows: [],
                counts: 0,
                currentPage: 1,
                pageSize: 20,
                //报表查询分页使用
                currentPageMid: 1,
                pageSizeMid: 15,
                countsMid: 0,
                myMap: new Map(),
                userList: [],
                roleList: [],
                megerList: [],
                reportToData: {},//测试用
                tabsName: 'reportList',
                userPermCode: {},//用户权限编码
                staffId: '',//用户编码
            };
        },
        methods: {

            isInArray3(value) {
                if (this.userPermCode.indexOf && typeof(this.userPermCode.indexOf) == 'function') {
                    var index = this.userPermCode.indexOf(value);
                    if (index >= 0) {
                        return true;
                    }
                }
                return false;
            },

            /**
             *测试用户权限
             */
            async getUserInfo() {
                let STAFF_ID = this.$utils.getUrlKey("STAFF_ID");
                let OPERATE_TIME = this.$utils.getUrlKey("OPERATE_TIME");
                let TRADE_ID = this.$utils.getUrlKey("TRADE_ID");
                let SIGNMSG = this.$utils.getUrlKey("SIGNMSG");
                let channel = 'reportManage';
                this.staffId = STAFF_ID
                if (STAFF_ID == "1" || this.pression == false) {
                    var all = {
                        name: "全部",
                        value: ''
                    }
                    this.searchReport();
                    this.getDictByCodeAndVal();
                    var arry = new Array();
                    arry.push(all);
                    this.statusSelect.options = arry;
                    this.categorySelect.options = arry;
                    await this.initCategorySelect(true);
                    //为了让窗口完全显示出来，在后面关闭时不会因为浏览器出问题，提前一个异步操作打开此窗口
                    this.designPops.centerDialogVisible = true;
                    await this.initStatusSelect(true);
                    //要把弹窗的组件显示加载后 才会refs调用到子组件方法
/*                    this.designPops.centerDialogVisible = true;
                    //修改隐藏弹窗属性
                    this.popsHide = true;*/
                    //在DOM执行刷新后调用关闭弹窗
                    this.$nextTick(function () {
                        this.designPops.centerDialogVisible = false
                        //修改隐藏弹窗属性
                    });
                } else {
                    let userinfo = await this.getUser(STAFF_ID, OPERATE_TIME, TRADE_ID, SIGNMSG, channel);
                    if (userinfo.isPression) {
                        this.userPermCode = userinfo.listUserPermCode
                        console.log(this.userPermCode)
                        var all = {
                            name: "全部",
                            value: ''
                        }
                        this.searchReport();
                        this.getDictByCodeAndVal();
                        var arry = new Array();
                        arry.push(all);
                        this.statusSelect.options = arry;
                        this.categorySelect.options = arry;
                        await this.initCategorySelect(true);
                        this.designPops.centerDialogVisible = true;
                        await this.initStatusSelect(true);
                        //要把弹窗的组件显示加载后 才会refs调用到子组件方法
/*                        this.designPops.centerDialogVisible = true;
                        //修改隐藏弹窗属性
                        this.popsHide = true;*/
                        //在DOM执行刷新后调用关闭弹窗
                        await this.$nextTick(function () {
                            this.designPops.centerDialogVisible = false;
                            //修改隐藏弹窗属性
                        });
                    } else {
                        this.$router.push({path: '/404', query: {msg: userinfo.msg}});
                    }
                }


            },
            queryReport(row) {
                //深克隆对象
                let paramsList = JSON.parse(JSON.stringify(row));
                this.queryTitle = paramsList.name;
                this.queryReportPops.name = paramsList.name;//弹窗名字（报表名字）
                this.queryReportPops.dsId = paramsList.dsId;
                this.queryReportPops.tableSql = paramsList.sqlText;
                this.queryReportPops.header = paramsList.header;
                this.queryReportPops.metaColumns = paramsList.metaColumns;//百分号处理，字典转换要用，所以要传给后台
                this.queryReportPops.reportParamList.params = JSON.parse(paramsList.params);
                this.reportToData = row;
                //以下注释因为之前是弹窗，现在改为tabs
                /*                let header = JSON.parse(paramsList.header);
                                console.log(header);
                                for (let head of header) {
                                    let heads = head.split("=");
                                    let nameAndfield = {
                                        name: heads[0],
                                        field: JSON.parse(heads[1]).field
                                    }
                                    this.queryReportPops.headerList.push(nameAndfield);
                                }
                                this.queryReportPops.reportParamList.views = this.queryReportPops.headerList;
                                for (let pas of this.queryReportPops.reportParamList.params) {
                                    this.$set(this.queryReportPops.paramMid, pas.sqlName + pas.type, "");
                                }*/

                this.searchMidBill();
                //这里2个参数，第一个是下面要合并参数，第二个是表头数据，因为下面要对比需要合并的行号和表头字段，详见下面解释
                this.mergeTable(paramsList.metaColumns,JSON.parse(paramsList.header));

                //this.queryReportPops.centerDialogVisible = true;
                //this.preview(row);
            },
            mergeTable(metaColumns,headerList) {
                this.megerList = [];//重置需要合并的列号
                let meta = JSON.parse(metaColumns);
                for (let i = 0; i < meta.length; i++) {
                    if ("true" == meta[i].isMergeCell) {
                        //这里比如{"name":"K","convertType":"1","convertValue":"","isPercent":"false","isMergeCell":"true","isEdit":"false"}
                        //K列需要合并，我们进入来，去对比表头的K，因为我们具体的列号是要以表头为准
                        for (let j = 0; j < headerList.length ;j++) {
                            //取表头==后面的部分的字段名和需要合并的字段名对比，如果相等，则记录下j也就是列号
                            if (JSON.parse(headerList[j].toString().split("==")[1]).field == meta[i].name) {
                                this.megerList.push(j);
                            }
                        }
                    }
                }
                this.$refs.previewReport.megerTable(this.pageSizeMid, this.megerList);
            },
            async queryMidTable() {
                let params = {
                    paramMid: this.queryReportPops.paramMid,
                }
                params.paramMid.tableSql = this.queryReportPops.tableSql;
                params.paramMid.sizE = this.pageSizeMid;
                params.paramMid.currenT = this.currentPageMid;
                params.paramMid.dsiD = this.queryReportPops.dsId;
                params.paramMid.headeR = this.queryReportPops.header;
                params.paramMid.metaColumnS = this.queryReportPops.metaColumns;
                let replys = await queryMid(params);
                if (replys.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: replys.msg
                    });
                } else {
                    this.countsMid = replys.data.total;
                    this.currentPageMid = replys.data.pageNum;
                    this.previewReportPops.tableHeader = replys.data.header;
                    this.previewReportPops.tableData = replys.data.list;
                    //this.tableDataMid = replys.data.list;
                }
                this.tabsName = 'searchMid';
            },
            async searchMidBill() {
                let params = {
                    tableSql: this.queryReportPops.tableSql,
                    dsiD: this.queryReportPops.dsId
                }
                let replys = await searchMidBill(params);
                if (replys.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: replys.msg
                    });
                } else {
                    this.queryReportPops.paramMid.BILL_MONTH5 = replys.msg;
                    this.queryMidTable();
                }
            },
            async createMidExcel() {
                this.loading = true;

                let param = {
                    paramMid: this.queryReportPops.paramMid,
                }
                param.paramMid.tableSql = this.queryReportPops.tableSql;
                /*                params.paramMid.dsiD = this.queryReportPops.dsId;
                                params.paramMid.headeR = this.queryReportPops.header;*/
                param.paramMid.reportId = this.reportToData.id;
                let replys = await createMidExcel(param);
                if (replys.code == 500) {
                    this.loading = false;
                    this.$notify.error({
                        title: '错误',
                        message: replys.msg
                    });
                } else {
                    window.location.href = encodeURI("reportDownload/downLoadLocalPage2?uuid=" + replys.data.uuid + "&filename=" + replys.data.filename + "&createPath=" + replys.data.createPath + "&id=1" + "&page=2");
                    //window.location.href = "zte-report/reportDownload/downLoadLocalPage2?uuid=" +replys.data.uuid +"&filename="+replys.data.filename+"&createPath="+replys.data.createPath+"&id=1";
                    this.loading = false;
                }
            },
            async initDictSelect(dictCode) {
                var all = {
                    name: "全部",
                    value: ''
                }
                //初始化 状态下拉框
                let dictSelect = await this.getSysDictItem(dictCode);
                dictSelect.unshift(all);
                this.queryReportPops.options = dictSelect;
            },
            async initSqlSelect(dictCode) {
                var all = {
                    name: "全部",
                    value: ''
                }
                //初始化 状态下拉框
                let dictSelect = await this.getSysSql(dictCode);
                dictSelect.unshift(all);
                this.queryReportPops.options = dictSelect;
            },
            async initCategorySelect(bool) {
                if (bool) {
                    var all = {
                        name: "全部",
                        value: ''
                    }
                    //初始化 sqlCode
                    var categorySelect = await this.getSysSql('REPORT_CATEGORY_NAME');
                    categorySelect.unshift(all);
                    this.categorySelect.options = categorySelect;
                }
            },
            async initStatusSelect(bool) {
                if (bool) {
                    var all = {
                        name: "全部",
                        value: ''
                    }
                    //初始化 状态下拉框
                    var result = await this.getSysDictItem('SERVICE_INTERFACE_STATUS');
                    result.unshift(all);
                    this.statusSelect.options = result;
                }
            },
            async initTable(id) {
                this.categorySelect.chooseValue = id;
                await this.initCategorySelect(true);
                await this.initStatusSelect(true);
                this.searchReport();
            },
            //监听页面变化
            handleSizeChange(val) {
                this.pageSize = val;
                this.searchReport();
            },
            //监听页面变化_报表查询
            handleSizeChangeMid(val) {
                this.pageSizeMid = val;
                this.queryMidTable();
            },
            //监听页面选择变化
            handleCurrentChange(val) {
                this.currentPage = val;
                this.searchReport();
            },
            //监听页面选择变化_报表查询
            handleCurrentChangeMid(val) {
                this.currentPageMid = val;
                this.queryMidTable();
            },
            //监听多选变化
            selectionChange(val) {
                this.selectRows = val;
            },
            /**
             * 获取字典信息
             */
            async getDictByCodeAndVal() {
                var params2 = {
                    type: 'dict',
                    dictCode: "REPORT_STATUS"
                };
                let dictSQL = await ListSysDict(params2);
                dictSQL.forEach(dict => {
                    this.myMap.set(dict.VALUE, dict.NAME);
                })
            },
            //查询报表配置
            async searchReport() {
                const loading = this.$loading({
                    lock: true,
                    text: '加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                let STAFF_ID = this.$utils.getUrlKey("STAFF_ID");
                var params = {
                    current: this.currentPage,
                    size: this.pageSize,
                    name: this.name,
                    status: this.statusSelect.chooseValue,
                    categoryId: this.categorySelect.chooseValue,
                    userId: STAFF_ID
                }
                let reply = await getReportList(params);
                loading.close();
                if (reply.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: reply.msg
                    });
                } else {
                    this.counts = reply.data.total;
                    this.currentPage = reply.data.pageNum;
                    this.tableData = reply.data.list;
                }
            },
            //table字段转换
            statusFormatter: function (row, column) {
                return this.myMap.get(row.status)
                //return row.status == "00A" ? "启用" : row.status == "00X" ? "禁用" : "未知";
            },
            //新增 报表配置
            async addReportConfig() {
                //修改隐藏弹窗属性
                this.popsHide = false;
                var params = {
                    id: '',
                    dataSourceValue: '',
                    sqlText: '',
                    statusValue: '',
                    reportDataValue: '',
                    reportUploadValue: '',
                    name: '',
                    excelTitle: '',
                    categoryId: '',
                    header: '',
                    metaColumns: '',
                    headTemp: '',
                    endTemp: '',
                    isEdit: false
                };
                this.designPops.title = "新增";
                this.$refs.reportDesign.initMethod(params);
                this.designPops.centerDialogVisible = true;
            },
            //批量删除
            batchDel() {
                if (this.selectRows.length < 1) {
                    this.$message.error('请勾选数据后，再批量删除！');
                    return;
                }
                this.$msgbox({
                    title: '提示',
                    message: "此操作将删除勾选数据, 是否继续?",
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose: async (action, instance, done) => {
                        if (action === 'confirm') {
                            this.removeReport(this.selectRows);
                        }
                        done();
                    }
                }).then(action => {
                });
            },
            //合并发布
            totalPublish() {
                if (this.selectRows.length < 2) {
                    this.$message.error('请至少勾选2项！');
                    return;
                }
                let uploadId = '';
                for (let selectRow of this.selectRows) {
                    if (uploadId) {
                        if (uploadId != selectRow.reportUploadId) {
                            this.$message.error('上传路径不一样，请检查！');
                            return;
                        }
                    } else {
                        uploadId = selectRow.reportUploadId;
                    }
                }
                this.$msgbox({
                    title: '提示',
                    message: "此操作将合并发布勾选数据, 是否继续?",
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose: async (action, instance, done) => {
                        if (action === 'confirm') {
                            this.publishMerge(this.selectRows);
                        }
                        done();
                    }
                }).then(action => {
                });
            },
            //批量发布
            publishRows() {
                if (this.selectRows.length < 1) {
                    this.$message.error('请勾选数据后，再批量发布！');
                    return;
                }
                this.$msgbox({
                    title: '提示',
                    message: "此操作将发布勾选数据, 是否继续?",
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose: async (action, instance, done) => {
                        if (action === 'confirm') {
                            this.publish(this.selectRows);
                        }
                        done();
                    }
                }).then(action => {
                });
            },
            //点击表格每行的发布
            publishRow(row) {
                var arry = new Array();
                arry.push(row);
                this.$msgbox({
                    title: '提示',
                    message: "此操作将发布该条数据, 是否继续?",
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose: async (action, instance, done) => {
                        if (action === 'confirm') {
                            this.publish(arry);
                        }
                        done();
                    }
                }).then(action => {
                });

            },
            //报表权限设置
            async authorityRow(row) {

                let param = {
                    reportId: row.id
                }
                let reply = await getReportPermission(param);
                this.permissionForm.userId = reply.userIds;
                this.permissionForm.roleId = reply.roleIds;
/*                //数组展示，结果返回回来是，分割
                if (reply.userId) {
                    reply.userId = reply.userId.substring(0, reply.userId.lastIndexOf(','));
                    this.permissionForm.userId = reply.userId.split(",");
                } else {
                    this.permissionForm.userId = [];
                }
                if (reply.roleId) {
                    reply.roleId = reply.roleId.substring(0, reply.roleId.lastIndexOf(','));
                    this.permissionForm.roleId = reply.roleId.split(",");
                } else {
                    this.permissionForm.roleId = [];
                }*/
                this.permissionPops.centerDialogVisible = true;
                this.reportId = row.id;
            },
            //获取用户列表和角色列表
            async getUserAndRoleList() {
                let reply = await getUserAndRoleList();
                this.userList = reply.user;
                this.roleList = reply.role;
            },
            //提交报表权限
            async submitPermission() {
                let userid = null;
                console.log(this.permissionForm.userId.toString());
                let param = {
                    userId: this.permissionForm.userId.toString(),
                    roleId: this.permissionForm.roleId.toString(),
                    reportId: this.reportId
                }
                let reply = await setUserAndRole(param);
                if (reply.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: reply.msg
                    });
                } else {
                    this.$notify.success({
                        title: "成功",
                        message: "权限设置成功！"
                    });
                }
                /*                if (this.permissionForm.userId != '') {
                                        userid = this.permissionForm.userId.toString() + ','
                                    }
                                    let roleId = null;
                                    if (this.permissionForm.roleId != '') {
                                        roleId = this.permissionForm.roleId.toString() + ','
                                    }
                                    let param = {
                                        userId: userid,
                                        roleId: roleId,
                                        reportId: this.reportId
                                    }
                                    if (reply.code == 500) {
                                        this.$notify.error({
                                            title: '错误',
                                            message: reply.msg
                                        });
                                    } else {
                                        this.$notify.success({
                                            title: "成功",
                                            message: "权限设置成功！"
                                        });
                                    }*/
                this.reportId = '';
                this.permissionPops.centerDialogVisible = false;
            },
            closePermission() {
                this.$refs['permissionForm'].resetFields();
                this.permissionPops.centerDialogVisible = false;
            },
            //点击删除
            removeRow(row) {
                var arry = new Array();
                arry.push(row);
                this.$msgbox({
                    title: '提示',
                    message: "此操作将删除该条数据, 是否继续?",
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose: async (action, instance, done) => {
                        if (action === 'confirm') {
                            this.removeReport(arry);
                        }
                        done();
                    }
                }).then(action => {
                });
            },
            //合并发布的方法
            async publishMerge(arry) {
                const loading = this.$loading({
                    lock: true,
                    text: '加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                let reply = await publishMerge(arry);
                loading.close();
                if (reply.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: reply.msg
                    });
                } else {
                    this.$notify.success({
                        title: "合并发布成功",
                        message: "请在报表进度查看,报表生成进度"
                    });
                    this.$refs.reportManageTable.clearSelection();
                }
            },
            //发布执行的方法
            async publish(arry) {
                const loading = this.$loading({
                    lock: true,
                    text: '加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                let reply = await publishReport(arry);
                loading.close();
                if (reply.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: reply.msg
                    });
                } else {
                    this.$notify.success({
                        title: "发布成功",
                        message: "请在报表进度查看,报表生成进度"
                    });
                    this.$refs.reportManageTable.clearSelection();
                }
            },
            async removeReport(arry) {
                const loading = this.$loading({
                    lock: true,
                    text: '加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                let reply = await delReport(arry);
                loading.close();
                if (reply.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: reply.msg
                    });
                } else {
                    this.$notify.success({
                        message: "删除成功"
                    });
                    this.$refs.reportManageTable.clearSelection();
                }
                this.searchReport();
            },
            //修改 每行报表
            async editRow(row) {
                this.designPops.centerDialogVisible = true;
                this.popsHide = false;
                var params = {
                    id: row.id,
                    dataSourceValue: row.dsId,
                    statusValue: row.status,
                    reportDataValue: row.reportDataId,
                    reportUploadValue: row.reportUploadId,
                    sqlText: row.sqlText,
                    params: JSON.parse(row.params),
                    name: row.name,
                    excelTitle: row.excelTitle,
                    categoryId: row.categoryId,
                    header: row.header,
                    metaColumns: row.metaColumns,
                    headTemp: row.headTemp,
                    endTemp: row.endTemp,
                    isEdit: true
                };
                this.designPops.title = "修改";
                this.$refs.reportDesign.initMethod(params);
                this.designPops.centerDialogVisible = true;
            },
            //关闭弹窗执行操作
            closePop() {
                this.designPops.centerDialogVisible = false;
                this.searchReport();
            },
            async preview(row) {
                /*var arry = JSON.parse(row.header);*/
                const loading = this.$loading({
                    lock: true,
                    text: '加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                //深克隆对象
                var params = JSON.parse(JSON.stringify(row));
                params.createTime = null;
                params.updateTime = null;
                let reply = await previewReport(params);

                loading.close();
                if (reply.code == 500) {
                    this.$notify.error({
                        title: '错误',
                        message: reply.msg
                    });
                } else {
                    this.previewReportPops.tableHeader = reply.data.header;
                    this.previewReportPops.tableData = reply.data.list;
                    this.previewReportPops.centerDialogVisible = true;
                }
            },
            handleClick(tab, event) {
                console.log(tab, event);
            },
        }
    }
</script>

<style scoped>
</style>